package org.springframework.boot.autoconfigure.datasource.druid;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.springframework.boot.autoconfigure.datasource.AbstractDataSourceConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.malaoshi.sprout.ioc.DefaultSingletonBeanRegistry;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

public class DruidConfig extends AbstractDataSourceConfig {
    private final static String PREFIX = "spring.datasource.druid";
    public void handle() throws Exception {
        Map<String,Object> map = new HashMap<>();

        putConfig(map,PREFIX);

        DataSource dataSource = DruidDataSourceFactory.createDataSource(map);
        DefaultSingletonBeanRegistry.me().registerSingletonObject("dataSource",dataSource);
    }

}
